﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace PIS.TechGrid.Gadgets.ChangeIP
{
    [Serializable]
    public class MyIPConfigList
    {
        private MyList<IPConfigList> ipConfigLists;

        public MyIPConfigList()
        {
            ipConfigLists = new MyList<IPConfigList>();
        }

        public MyIPConfigList(MyList<IPConfigList> configList)
        {
            ipConfigLists = configList;
        }

        public MyList<IPConfigList> IPConfigLists
        {
            get
            {
                return ipConfigLists;
            }
        }

        public void Add(IPConfigList cfgList)
        {
            IPConfigList cfgl = Get(cfgList.Name);
            if (cfgl != null)
            {
                throw new Exception(String.Format("The IP configuration list {0} already exists", cfgList.Name));
            }

            IPConfigLists.Add(cfgList);
        }

        public void Remove(string name)
        {
            IPConfigList cfgList = this.Get(name);

            if (cfgList != null)
            {
                this.IPConfigLists.Remove(cfgList);
            }
        }

        public IPConfigList Get(string name)
        {
            foreach (IPConfigList cfgList in IPConfigLists)
            {
                if (name == cfgList.Name)
                {
                    return cfgList;
                }
            }

            return null;
        }
    }
}
